/*
 * @Author: zhangweixin 
 * @Date: 2018-11-07 16:50:37 
 * @Last Modified by: zhangweixin
 * @Last Modified time: 2018-11-29 17:26:28
 */
const path = require('path');
var webpack = require('webpack');
const merge = require('webpack-merge');
const commonConfig = require('./webpack.common.config.js');
var UglifyjsPlugin = require('uglifyjs-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

let proConfig = {
  devtool:"cheap-module-source-map",
  module:{
    rules:[
      {
        test:/\.less$/,
        use: ExtractTextPlugin.extract({
          fallback: "style-loader",
          use: ['css-loader?modules&localIdentName=[local]-[hash:base64:5]','postcss-loader','less-loader']
        }),
        exclude:path.join(__dirname,'node_modules'),
      },
    ]
  },
  resolve:{
    alias:{
      ENV:path.join(__dirname,'src/config/env.prod.js'),
    }
  },
  plugins:[
    new CleanWebpackPlugin(['dist/*.*']),
    new webpack.DefinePlugin({
      'process.env': {
          'NODE_ENV': JSON.stringify('production')
       }
   }),
    new UglifyjsPlugin({
      compress:{
        warnings:false,
        drop_console:true, // 删除console
        drop_debugger: true, // remove debugger
      }
    }),
    new ExtractTextPlugin({
      filename: '[name].[contenthash:5].css',
      allChunks: true
    })
  ]
}
module.exports = merge(commonConfig,proConfig)